/**
 * Created by Freeman on 2016/7/1.
 */
"use strict";

import {GET_ARTICLE_LIST_FAILURE,GET_ARTICLE_LIST_SUCCESS,REQUEST_ARTICLE_LIST,ADD_ARTICLE_LIST,DELETE_ARTICLE_SUCCESS} from '../types'

const state = {
    items:[],
    isFetching:false,
    isMore:true
}
const mutations = {
    [REQUEST_ARTICLE_LIST](state){
        state.isFetching = true
    },
    [GET_ARTICLE_LIST_SUCCESS](state,action){
        state.isFetching = false
        state.items = action.articleList
        state.isMore = action.isMore
    },
    [GET_ARTICLE_LIST_FAILURE](state){
        state.isFetching = false
    },
    [ADD_ARTICLE_LIST](state,action){
        state.isFetching = false
        state.isMore = action.isMore
        state.items = [...state.items,...action.articleList]
    },
    [DELETE_ARTICLE_SUCCESS](state,action){
        state.items = state.items.filter(item=>{
            return item._id !== action.id
        })
    }
}

export default {
    state,
    mutations
}